package com.control.demo;

import java.util.HashMap;
import com.control.R;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestSoundsActivity extends Activity {
	 private Button bPlay;
	 private Button bPause;
	 private SoundPool sp;
	 private HashMap<Integer,Integer> spMap;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_test);
        
        
        bPlay = (Button)findViewById(R.id.button01);
        bPause = (Button)findViewById(R.id.button02);
        sp = new SoundPool(2,AudioManager.STREAM_MUSIC,0);
        spMap = new HashMap<Integer,Integer>();
        spMap.put(1, sp.load(this,R.raw.notice_, 1));
        
        bPlay.setOnClickListener(new OnClickListener() {        
            public void onClick(View v) {
                playSounds(1,1);
            }
        });
        
        bPause.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                sp.pause(spMap.get(1));
            }
        });        
    }
    
    
    public void playSounds(int sound, int number){
    	sp.release();
        AudioManager am = (AudioManager)this.getSystemService(this.AUDIO_SERVICE);
        float audioMaxVolumn = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        float audioCurrentVolumn = am.getStreamVolume(AudioManager.STREAM_MUSIC);
        float volumnRatio = audioCurrentVolumn/audioMaxVolumn;
        sp.play(spMap.get(sound), volumnRatio, volumnRatio, 1, number, 1);
    }
}